package com.aaa.service.log.impl;

import com.aaa.dao.log.LogDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.log.Log;
import com.aaa.entity.sas.QuestionSas;
import com.aaa.service.log.LogService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Log)表服务实现类
 *
 * @author makejava
 * @since 2022-09-06 14:09:22
 */
@Service("logService")
public class LogServiceImpl implements LogService {
    @Resource
    private LogDao logDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Log queryById(Integer id) {
        return this.logDao.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param log 实例对象
     * @return 实例对象
     */
    @Override
    public Log insert(Log log) {
        this.logDao.insert(log);
        return log;
    }

    /**
     * 修改数据
     *
     * @param log 实例对象
     * @return 实例对象
     */
    @Override
    public Log update(Log log) {
        this.logDao.update(log);
        return this.queryById(log.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.logDao.deleteById(id) > 0;
    }

    @Override
    public Page queryAllByPage(PageSortEntity pageSortEntity, Log log) {
        PageHelper.startPage(pageSortEntity.getPage(),pageSortEntity.getLimit(),pageSortEntity.getOrderString());
        List<Log> logs = logDao.queryAllByPage();
        Page<Log> page = (Page) logs;
        return page;
    }
}
